package cn.usian.jyzx.product.controller;

import cn.usian.jyzx.model.dto.h5.ProductSkuDto;
import cn.usian.jyzx.model.entity.product.Category;
import cn.usian.jyzx.model.entity.product.ProductSku;
import cn.usian.jyzx.model.vo.common.Result;
import cn.usian.jyzx.model.vo.common.ResultCodeEnum;
import cn.usian.jyzx.model.vo.h5.IndexVo;
import cn.usian.jyzx.product.service.CategoryService;
import cn.usian.jyzx.product.service.ProductService;
import cn.usian.jyzx.product.service.ProductSkuService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @TODO:
 * @Author:baimu
 * @Date:2024 06 12 17 12
 **/
@RestController
@RequestMapping("/api/product")
@Tag(name = "商品相关接口")
@Slf4j
@CrossOrigin
public class ProductController {
   @Autowired
   CategoryService categoryService;

   @Autowired
   ProductSkuService productSkuService;

   @Autowired
   ProductService productService;



   @GetMapping("/index")
   @Operation(summary = "查询首页数据")
   public Result index(){
      List<Category> oneLevel = categoryService.findOneLevel();
      log.info("oneLevel:{}",oneLevel);
      List<ProductSku> goodSaleSku = productSkuService.findGoodSaleSku();
      log.info("goodSaleSku:{}",goodSaleSku);
      IndexVo indexVo = new IndexVo();
      indexVo.setCategoryList(oneLevel);
      indexVo.setProductSkuList(goodSaleSku);

      return Result.build(indexVo, ResultCodeEnum.SUCCESS);


   }


   @Operation(summary = "分页查询")
   @GetMapping(value = "/{page}/{limit}")
   public Result<PageInfo<ProductSku>> findByPage(@PathVariable Integer page,
                                                  @PathVariable Integer limit,
                                                  ProductSkuDto productSkuDto) {
      PageInfo<ProductSku> pageInfo = productService.findByPage(page, limit, productSkuDto);
      return Result.build(pageInfo , ResultCodeEnum.SUCCESS) ;
   }


}
